import React, { Component } from 'react'
import '../assert/css/login.css'
import Header from '../components/DefaultHeader'

export default class Login extends Component {
    state={
        phone:'',
        password:''
    }
    componentWillUnmount() {
      this.setState = () => false //重置了setState
  }
    submit(){
      const {phone,password} =this.state

        if(phone==''){
            return alert('手机号不能为空')
         }
         if(password==''){
             return alert('密码不能为空')
         }
        this.$axios.post('/login',{phone,password}).then(res=>{
            
            if(res.code==200 && res.msg=='登录成功'){
                localStorage.setItem('login_data',JSON.stringify(res.list) )
               this.props.history.push('/uncenter')
               this.setState({phone:'',password:''})
               this.props.getcartlist1()
            }
        })
    }
  render() {
      const {phone,password} =this.state
    return (
      <>
        <div className="login-container">
          <Header title='会员登录' right_text='注册' right_method={()=>this.props.history.push('/reg')}/>
        <div className="logo"></div>
        <div className="form">

            <div className="form-group">
                <input type="text" value={phone} onChange={(e)=>this.setState({phone:e.target.value})} placeholder="手机号" />
            </div>
            <div className="form-group">
                <input type="password" value={password} onChange={(e)=>this.setState({password:e.target.value})} placeholder="密码" />
            </div>
            <div className="form-group">
                <button className="btn-gray" onClick={()=>this.submit()}>登录</button>
            </div>
        </div>
    </div>
      </>
    )
  }
}
